const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')

let mainWindow

function createWindow() {
    mainWindow = new BrowserWindow({
        width: 1200,
        height: 800,
        webPreferences: {
            preload: path.join(__dirname, '../shared/preload.js'),
            contextIsolation: true,
            enableRemoteModule: false,
            nodeIntegration: false
        }
    })

    if (process.env.NODE_ENV === 'development') {
        mainWindow.loadURL('http://localhost:3000')
        mainWindow.webContents.openDevTools()
    } else {
        mainWindow.loadFile(path.join(__dirname, '../renderer/dist/index.html'))
    }
}

app.whenReady().then(createWindow)

ipcMain.handle('decompile-js', (event, jsCode) => {
    return decompileJs(jsCode)
})

function decompileJs(jsCode) {
    // 这里实现反编译逻辑，后面会详细说明
    return {
        componentCode: '...',
        templateCode: '...',
        styleCode: '...'
    }
}